<template>
	<el-dialog title="新增成单" :visible.sync="value" width="370px" :before-close="beforeClose">
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="成单类型" prop="contractType">
				<el-select v-model="form.contractType" placeholder="请选择">
					<el-option v-for="item in contractTypeDict" :key="item.value" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="成单金额" prop="contractAmount">
				<el-input v-model="form.contractAmount" placeholder="请输入"></el-input>
			</el-form-item>
			<el-form-item label="成单时间" prop="contractCreateTime">
				<el-date-picker
          v-model="form.contractCreateTime"
          type="date"
					placeholder="选择日期"
        ></el-date-picker>
			</el-form-item>
			<el-form-item label="备注" prop="contractRemark">
				<el-input v-model="form.contractRemark" placeholder="请输入"></el-input>
			</el-form-item>
		</el-form>
		<el-button class="submit-btn" @click="submit">
			提交
			<i class="el-icon-arrow-right"></i>
		</el-button>
	</el-dialog>
</template>
<script>
	import {
		commitContractRecord
	} from '@/api/enterprise'
	export default {
		props: {
			value: {
				type: Boolean,
				default: false
			},
			unitOrgCode: {
				type: String,
				default: () => ''
			}
		},
		watch: {
			unitOrgCode(code) {
				if (code) {
					this.form.unitOrgCode = code
				}
			}
		},
		data() {
			return {
				form: {
					unitOrgCode: '',
					contractType: '',
					contractAmount: '',
					contractCreateTime: '',
					contractRemark: '',
				},
			}
		},
		computed: {
			contractTypeDict() {
				const dict = this.$store.getters.dict
				const list = []
				for (let value in dict.contractType) {
					list.push({
						label: dict.contractType[value],
						value
					})
				}
				return list
			}
		},
		methods: {
			submit() {
				commitContractRecord(this.form).then((res) => {
					this.$message.success('操作完成')
					this.beforeClose()
				})
			},
			beforeClose() {
				this.form = {
					taskIdList: [],
					recordId: '',
					enterpriseId: '',
					isPass: true
				};
				this.$emit('input', false)
			}
		}
	}
</script>
<style lang="scss" scoped>
	::v-deep .el-dialog .el-dialog__body {
		padding: 30px 0 0;
	}

	.el-form {
		padding: 0 10px;
	}

	.check-list {
		padding: 0 40px;
	}

	.submit-btn {
		width: 100%;
		height: 44px;
		background: #1c4088;
		box-shadow: 0px 4px 48px 32px rgba(6, 23, 80, 0.05);
		border-radius: 0;
		color: #ffffff;
		border: none;
	}
</style>